// fenxiao/index/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */

  data: {
    lists: {},
    isred: false,
    showJJKData: false,
    showExpander: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getCityBoss();
    this.getRegionVersion();
  },

  //是否可以查看玖玖卡数据（拓展员玖玖卡数据）
  getCityBoss: function () {
    let that = this;
    wx.request({
      url: app.globalData.host + '/api/distributor/GetDisRegionList?showCount=0&uid=' + app.globalData.userInfo.Uid,
      success: function (res) {
        if (res.data.Code == 0) {
          if (res.data.Data && res.data.Data.length > 0) {
            that.setData({
              showJJKData: true
            })
          }
        }
      }
    })
  },
  //获取分销商信息，如果分销商不存在，则创建新的
  GetDistributorInfo: function () {
    var that = this;
    var disId = wx.getStorageSync('disid')
    var agentId = wx.getStorageSync('agentid')
    if (disId == "" || disId == null) {
      disId = 0
    }
    if (agentId == "" || agentId == null) {
      agentId = 0
    }
    wx.request({
      url: app.globalData.host + '/api/Distributor/GetDistributorAndCreate',
      data: {
        userId: app.globalData.userInfo.Uid,
        disId: disId,
        agentId: agentId,
        storeId: app.globalData.storeId
      },
      success: function (res) {
        if (res.data.Code == 0) {
          var list = res.data.Data;
          list.totalClickCount = (parseInt(list.StaffClickCount) + parseInt(list.ChildStaffClickCount)) //粉丝总数 = 自己人脉粉丝 + 下级的人脉粉丝
          that.setData({
            lists: list
          })
        } else {
          wx.showModal({
            title: '提示',
            content: res.data.Message,
            showCancel: false
          })
        }
      }
    })
  },

  //获取拓展员版本(区域玖玖卡数据)
  getRegionVersion: function () {
    let that = this;
    wx.request({
      url: app.globalData.host + '/api/staff/GetRegionVersion?uid=' + app.globalData.userInfo.Uid,
      success: function (res) {
        if (res.data.Code == 0) {
          if (res.data.Data) {
            if (res.data.Data.upgrade.level == 6) {
              that.setData({
                showExpander: true
              })
            }
          }
        }
      },
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.GetDistributorInfo();
    this.getMyPayRequests();
  },

  //获取待确认列表
  getMyPayRequests: function () {
    let that = this;
    wx.request({
      url: app.globalData.host + '/api/Staff/GetMyPayRequests?uid=' + app.globalData.userInfo.Uid + '&status=0' + '&page=1',
      success: function (res) {
        if (res.data.Code == 0) {
          let list = res.data.Data;
          if (list.length > 0) {
            that.setData({
              isred: true
            })
          } else {
            that.setData({
              isred: false
            })
          }
        }
      }
    })
  }
})